#include "coverableBlob.h"


void coverableBlob::setup(int w, int h){
	width = w;
	height = h;
	meAsGray.allocate(width, height);
	meAndedWithHand.allocate(width, height);
	meAsGray.set(0);
	randomAngle = ofRandom(-1,1);
	bTriggered = false;
	targetx = 50;
	targety = 50;
	energy	= 0;
	bTraveling = false;
}

void  coverableBlob::clear(){
	randomAngle = ofRandom(-1,1);
	targetx = 50;
	targety = 50;
	energy	= 0;
	bTraveling = false;
	meAsGray.set(0);
	
}
		

//--------------------------------------------------------------
void  coverableBlob::checkCoverage(videoHandDetector * vhd){	
	update();
	draw(meAsGray, 255);
	meAndedWithHand = meAsGray;
	meAndedWithHand &= vhd->handDetectionImage;

	int meCount = meAsGray.countNonZeroInRegion(0,0,width, height);
	int andCount = meAndedWithHand.countNonZeroInRegion(0,0,width, height);
		
	if (meCount == andCount){
		nFramesCovered++;	
	} else {
		nFramesCovered = 0;
	}
	if (nFramesCovered > 5){
		bTriggered = true;
	}
	//printf("nFramesCovered = %i \n", nFramesCovered);
}
		